﻿#region summary
// Copyright (c)  MOKEYISH. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
#endregion

using System;
using System.Text;
using Microsoft.JSInterop;
using NSQL.Parser;

namespace NSQL.Web
{
    public class Examples
    {
        [JSInvokable]
        public static dynamic AddNumbers(int a, int b)
        {
            Console.WriteLine($"可以吗, {a+b}={a}+{b}");
            return new {a, b};
        }

        [JSInvokable]
        public static dynamic ParseExpression(string exp)
        {
            Console.WriteLine("解析表达式");
            return Json.Serialize(SqlParser.ParseExpression(exp));
        }
        
        [JSInvokable]
        public static dynamic ParseLogicalExpression(string exp)
        {
            Console.WriteLine("解析逻辑表达式");
            return Json.Serialize(SqlParser.ParseLogicalExpression(exp));
        }

        public static string RepeatString(string str, int count)
        {
            var result = new StringBuilder();

            for (var i = 0; i < count; i++)
            {
                result.Append(str);
            }

            return result.ToString();
        }

        public static void TriggerException(string message)
        {
            throw new InvalidOperationException(message);
        }
    }
}